#pragma once

#include "object/transport.h"

class Map;
namespace battle::object
{

	class GlobalTransport : public battle::object::Transport
	{
    public:
        explicit GlobalTransport();
        virtual ~GlobalTransport();
        virtual void Update(unsigned int update_diff, unsigned int p_time) override;

        bool Initialize(unsigned int entry, unsigned int period, std::string const& name);
        std::set<unsigned int> const* GetMapsUsed() const { return &m_mapsUsed; }

    private:
        bool GenerateWaypoints();
        void TeleportTransport(unsigned int newMapid, float x, float y, float z);
        void UpdateForMap(Map const* map);
        void MoveToNextWayPoint();                          // move m_next/m_cur to next points

    private:
        struct WayPoint
        {
            WayPoint() : mapid(0), x(0), y(0), z(0), teleport(false) {}
            WayPoint(unsigned int _mapid, float _x, float _y, float _z, bool _teleport) :
                mapid(_mapid), x(_x), y(_y), z(_z), teleport(_teleport) {
            }
            unsigned int mapid;
            float x;
            float y;
            float z;
            bool teleport;
        };

        typedef std::map<unsigned int, WayPoint> WayPointMap;

        WayPointMap m_WayPoints;
        WayPointMap::const_iterator m_curr;
        WayPointMap::const_iterator m_next;

        std::set<unsigned int> m_mapsUsed;

        unsigned int m_pathTime;
        unsigned int m_timer;
        unsigned int m_nextNodeTime;
        unsigned int m_period;
	};

}
